package com.henu.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.henu.R;
import com.henu.tanhang.entity.Detail;

import java.util.ArrayList;
import java.util.Collections;

/**
 * Created by th on 2017/5/22.
 */

public class CheckallAdapter extends BaseAdapter {

    private ArrayList<Detail> list=new ArrayList<>();
    LayoutInflater inflater;

    public CheckallAdapter(Context context){
        inflater=LayoutInflater.from(context);
    }
    public void addData(ArrayList<Detail> templist)
    {
        list.clear();
        list.addAll(templist);
        Collections.reverse(list);
    }
    public void addAll(ArrayList<Detail> templist){
       list.addAll(templist);
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        if(view==null)
        {
            view= inflater.inflate(R.layout.infater_checkall,null);
        }

        TextView tv_checkname= (TextView) view.findViewById(R.id.tv_checkname);
        TextView tv_checkaddress= (TextView) view.findViewById(R.id.tv_checkaddress);
        TextView tv_checkphone= (TextView) view.findViewById(R.id.tv_checkphone);
        ImageView iv_check = (ImageView)view.findViewById(R.id.iv_check);
        if(i%7 == 0){
            iv_check.setImageResource(R.drawable.hotel1);
        }else if(i%7 == 1){
            iv_check.setImageResource(R.drawable.hotel2);
        }else if(i%7 == 2){
            iv_check.setImageResource(R.drawable.hotel3);
        }else if(i%7 == 3){
            iv_check.setImageResource(R.drawable.hotel4);
        }else if(i%7 == 4){
            iv_check.setImageResource(R.drawable.hotel5);
        }else if(i%7 == 5){
            iv_check.setImageResource(R.drawable.hotel6);
        }else if(i%7 == 6){
            iv_check.setImageResource(R.drawable.hotel7);
        }

        Detail detail =list.get(i);
        tv_checkname.setText(detail.getCheckname());
        tv_checkaddress.setText(detail.getAddress());
        tv_checkphone.setText(detail.getPhone());

        return view;
    }
}
